|
|
|
|
|
|
|
Figure 14.2.
Reporting the error
from CreateErr. |
|
|
|
|
|
|
|
|
When you click the OK button in the message box, you see another error message. This one reports an Error 53-File not found message, which occurred when CreateErr tried to open the nonexistent file (see Figure 14.3). |
|
|
|
|
|
|
|
|
Figure 14.3.
Reporting the File
not found error. |
|
|
|
|
|
|
|
|
Here's the important point. Notice that the second error message box tells you that the error is being reported from the cmdCascadeErr routineeven though the error occurred in the CreateErr routine! The error that occurred in the CreateErr error-handling routine could not be handled locally, and Visual Basic searched upward in the call stack to find the next available error handler to invoke. This action by Visual Basic can be a blessing and a curse. It's good to know that Visual Basic uses the next available error-handling routine when things like this happen, but it's also likely to cause confusion for you and your users if you are not careful. For all you can tell in this example, an error occurred in cmdCascadeErr. You must keep this in mind when you are debugging Visual Basic error reports. |
|
|
|
|
|
|
|
|
Using Resume to Exit the Error Handler |
|
|
|
|
|
|
|
|
The simplest way to exit an error handler is to use the Resume method. When you exit an error handler with the Resume keyword, Visual Basic returns to the line of code that caused the error and attempts to run that line again. The Resume keyword is useful when you encounter an error that the user can easily correct, such as attempting to read a disk drive when the user |
|
|
|
|
|